﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace VIB.View
{
    /// <summary>
    /// Interaction logic for BookInfo.xaml
    /// </summary>
    public partial class BookInfo : Window
    {
        private int IdBook { get; set; }
        private string Isbn { get; set; }
        new private string Title { get; set; }
        private string Author { get; set; }
        private int Year{ get; set; }


        public BookInfo(int idBook, string isbn, string author, string title, int year)
        {            
            IdBook = idBook;
            Isbn = isbn;
            Author = author;
            Title = title;
            Year = year;
            InitializeComponent();
        }

        private void Close(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        public void RefreshControlStatus()
        {
            textbox_isbn.Text = Isbn;
            textbox_author.Text = Author;
            textbox_title.Text = Title;
            textbox_year.Text = Year.ToString();
            try
            {
                if (combobox_timespan.SelectedItem == cbitem_30)
                {
                    textbox_borrowedTotal.Text = DataManager.GetTimesBorrowed(IdBook, 30).ToString();
                }
                else if (combobox_timespan.SelectedItem == cbitem_180)
                {
                    textbox_borrowedTotal.Text = DataManager.GetTimesBorrowed(IdBook, 180).ToString();
                }
                else if (combobox_timespan.SelectedItem == cbitem_365)
                {
                    textbox_borrowedTotal.Text = DataManager.GetTimesBorrowed(IdBook, 365).ToString();
                }
                textbox_averageBorrowTime.Text = Math.Round(DataManager.GetAverageBorrowTime(IdBook), 2).ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
          
        }

        private void combobox_timespan_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            RefreshControlStatus();
        }

        public void Show()
        {
            base.Show();
            RefreshControlStatus();
        }
    }
}
